home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / git-4.3 / git-4 / git-4.3.7 / src / signals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-08  |  2.6 KB  |  134 lines

  1. /* signal.c -- a file which should cantain some *REAL* signals management. */
  2.  
  3. /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. /* Written by Tudor Hulubei and Andrei Pitis.  */
  20.  
  21.  
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25.  
  26. #include <stdio.h>
  27.  
  28. #ifdef HAVE_STDLIB_H
  29. #include <stdlib.h>
  30. #else /* !HAVE_STDLIB_H */
  31. #include "ansi_stdlib.h"
  32. #endif /* !HAVE_STDLIB_H */
  33.  
  34. #include <signal.h>
  35.  
  36. #include "signals.h"
  37. #include "inputline.h"
  38. #include "tty.h"
  39. #include "misc.h"
  40.  
  41.  
  42. extern pid_t pid;
  43. extern char *screen;
  44. extern input_line_t *input;
  45.  
  46.  
  47. int suspend_allowed = OFF;
  48. int signals_status;
  49. int UserHeartAttack = 0;
  50.  
  51.  
  52. RETSIGTYPE
  53. suspend(signum)
  54.     int signum;
  55. {
  56.     signal(signum, suspend);
  57.  
  58.     if (suspend_allowed)
  59.     {
  60.         tty_set_mode(TTY_CANONIC);
  61.         tty_put_screen(screen);
  62.         kill(pid, SIGSTOP);
  63.     }
  64. }
  65.  
  66.  
  67. RETSIGTYPE
  68. resume(signum)
  69.     int signum;
  70. {
  71.     extern int current_mode;
  72.     extern void refresh_after_suspend __P((int));
  73.  
  74.     signal(signum, resume);
  75.  
  76.     refresh_after_suspend(current_mode);
  77. }
  78.  
  79.  
  80. RETSIGTYPE
  81. user_panic(signum)
  82.     int signum;
  83. {
  84.     signal(signum, user_panic);
  85.  
  86.     UserHeartAttack = 1; 
  87. }
  88.  
  89.  
  90. void
  91. signals_dfl()
  92. {
  93.     signal(SIGTERM, SIG_DFL);
  94.     signal(SIGQUIT, SIG_DFL);
  95.     signal(SIGINT , SIG_DFL);
  96. }
  97.  
  98.  
  99. void
  100. signals(status)
  101.     int status;
  102. {
  103.     signals_status = status;
  104.     signal(SIGTERM, status == ON ? fatal_signal : SIG_IGN);
  105.     signal(SIGQUIT, status == ON ? fatal_signal : SIG_IGN);
  106.     signal(SIGINT , status == ON ? user_panic   : SIG_IGN);
  107. }
  108.  
  109.  
  110. void
  111. ignore_signals()
  112. {
  113.     signal(SIGILL,  SIG_IGN);
  114.     signal(SIGTRAP, SIG_IGN);
  115.     signal(SIGABRT, SIG_IGN);
  116.     signal(SIGUSR1, SIG_IGN);
  117.     signal(SIGUSR2, SIG_IGN);
  118.     signal(SIGPIPE, SIG_IGN);
  119.     signal(SIGFPE,  SIG_IGN);
  120. }
  121.  
  122.  
  123. void
  124. restore_signals()
  125. {
  126.     signal(SIGILL,  SIG_DFL);
  127.     signal(SIGTRAP, SIG_DFL);
  128.     signal(SIGABRT, SIG_DFL);
  129.     signal(SIGUSR1, SIG_DFL);
  130.     signal(SIGUSR2, SIG_DFL);
  131.     signal(SIGPIPE, SIG_DFL);
  132.     signal(SIGFPE,  SIG_DFL);
  133. }
  134.